package cn.iocoder.yudao.module.biz.controller.admin.htPlanDetailexeannexs;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.htPlanDetailexeannexs.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.htPlanDetailexeannexs.HtPlanDetailexeannexsDO;
import cn.iocoder.yudao.module.biz.convert.htPlanDetailexeannexs.HtPlanDetailexeannexsConvert;
import cn.iocoder.yudao.module.biz.service.htPlanDetailexeannexs.HtPlanDetailexeannexsService;

@Api(tags = "管理后台 - 隐患排查计划执行结果附件")
@RestController
@RequestMapping("/biz/ht-plan-detailexeannexs")
@Validated
public class HtPlanDetailexeannexsController {

    @Resource
    private HtPlanDetailexeannexsService htPlanDetailexeannexsService;

    @PostMapping("/create")
    @ApiOperation("创建隐患排查计划执行结果附件")
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:create')")
    public CommonResult<Integer> createHtPlanDetailexeannexs(@Valid @RequestBody HtPlanDetailexeannexsCreateReqVO createReqVO) {
        return success(htPlanDetailexeannexsService.createHtPlanDetailexeannexs(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新隐患排查计划执行结果附件")
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:update')")
    public CommonResult<Boolean> updateHtPlanDetailexeannexs(@Valid @RequestBody HtPlanDetailexeannexsUpdateReqVO updateReqVO) {
        htPlanDetailexeannexsService.updateHtPlanDetailexeannexs(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除隐患排查计划执行结果附件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:delete')")
    public CommonResult<Boolean> deleteHtPlanDetailexeannexs(@RequestParam("id") Integer id) {
        htPlanDetailexeannexsService.deleteHtPlanDetailexeannexs(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得隐患排查计划执行结果附件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:query')")
    public CommonResult<HtPlanDetailexeannexsRespVO> getHtPlanDetailexeannexs(@RequestParam("id") Integer id) {
        HtPlanDetailexeannexsDO htPlanDetailexeannexs = htPlanDetailexeannexsService.getHtPlanDetailexeannexs(id);
        return success(HtPlanDetailexeannexsConvert.INSTANCE.convert(htPlanDetailexeannexs));
    }

    @GetMapping("/list")
    @ApiOperation("获得隐患排查计划执行结果附件列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:query')")
    public CommonResult<List<HtPlanDetailexeannexsRespVO>> getHtPlanDetailexeannexsList(@RequestParam("ids") Collection<Integer> ids) {
        List<HtPlanDetailexeannexsDO> list = htPlanDetailexeannexsService.getHtPlanDetailexeannexsList(ids);
        return success(HtPlanDetailexeannexsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得隐患排查计划执行结果附件分页")
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:query')")
    public CommonResult<PageResult<HtPlanDetailexeannexsRespVO>> getHtPlanDetailexeannexsPage(@Valid HtPlanDetailexeannexsPageReqVO pageVO) {
        PageResult<HtPlanDetailexeannexsDO> pageResult = htPlanDetailexeannexsService.getHtPlanDetailexeannexsPage(pageVO);
        return success(HtPlanDetailexeannexsConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出隐患排查计划执行结果附件 Excel")
    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detailexeannexs:export')")
    @OperateLog(type = EXPORT)
    public void exportHtPlanDetailexeannexsExcel(@Valid HtPlanDetailexeannexsExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<HtPlanDetailexeannexsDO> list = htPlanDetailexeannexsService.getHtPlanDetailexeannexsList(exportReqVO);
        // 导出 Excel
        List<HtPlanDetailexeannexsExcelVO> datas = HtPlanDetailexeannexsConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "隐患排查计划执行结果附件.xls", "数据", HtPlanDetailexeannexsExcelVO.class, datas);
    }

}
